<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>贝利亚拼好饭消消乐</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            flex-direction: column;
            align-items: center;
            background-color: #f0f0f0;
            margin: 0;
            padding: 20px;
        }
        .game-title {
            font-size: 32px;
            font-weight: bold;
            color: #ff6b6b;
            margin: 20px 0;
            text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
        }
        .game-content {
            display: flex;
            gap: 20px;
            align-items: flex-start;
            height: 800px;
        }
        .character-section {
            position: relative;
            width: 400px;
            height: 100%;
            display: flex;
            align-items: center;
        }
        .character {
            width: 100%;
            height: 100%;
            object-fit: cover;
            border-radius: 15px;
            box-shadow: 0 4px 8px rgba(0,0,0,0.2);
            animation: shake 0.5s infinite;
        }
        @keyframes shake {
            0% { transform: translate(0, 0) rotate(0deg); }
            25% { transform: translate(-2px, 2px) rotate(-1deg); }
            50% { transform: translate(2px, -2px) rotate(1deg); }
            75% { transform: translate(-2px, -2px) rotate(-1deg); }
            100% { transform: translate(0, 0) rotate(0deg); }
        }
        .speech-bubble {
            position: absolute;
            top: 20px;
            left: -300px;
            transform: none;
            background-color: white;
            padding: 20px 25px;
            border-radius: 25px;
            box-shadow: 0 4px 8px rgba(0,0,0,0.2);
            opacity: 0;
            transition: opacity 0.3s ease;
            white-space: nowrap;
            font-size: 22px;
            min-width: 300px;
            text-align: center;
            z-index: 10;
        }
        .speech-bubble::after {
            content: '';
            position: absolute;
            bottom: 20px;
            right: -20px;
            transform: rotate(90deg);
            border-width: 20px 20px 0;
            border-style: solid;
            border-color: white transparent transparent;
        }
        .speech-bubble.show {
            opacity: 1;
        }
        .game-container {
            width: 800px;
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        .score-board {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 10px;
            width: 100%;
            margin: 20px 0;
            padding: 15px;
            background-color: white;
            border-radius: 10px;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
        }
        .score-item {
            display: flex;
            align-items: center;
            padding: 5px;
            background-color: #f8f9fa;
            border-radius: 5px;
        }
        .score-item img {
            width: 30px;
            height: 30px;
            margin-right: 10px;
            border-radius: 50%;
            object-fit: cover;
        }
        .game-board {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 10px;
            width: 100%;
            padding: 20px;
            background-color: white;
            border-radius: 10px;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
        }
        .card {
            width: 100%;
            aspect-ratio: 1;
            background-color: #f8f9fa;
            border-radius: 10px;
            cursor: pointer;
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }
        .card img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            position: absolute;
            top: 0;
            left: 0;
            transition: transform 0.3s ease;
        }
        .card.selected {
            transform: scale(1.05);
            box-shadow: 0 0 15px rgba(255,107,107,0.5);
        }
        .card.matched {
            visibility: hidden;
        }
        .card:hover {
            transform: scale(1.02);
        }
        .modal-overlay {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
            z-index: 1000;
            justify-content: center;
            align-items: center;
        }
        .modal-content {
            background-color: white;
            padding: 30px;
            border-radius: 15px;
            text-align: center;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
            animation: modalAppear 0.3s ease-out;
        }
        @keyframes modalAppear {
            from {
                transform: scale(0.8);
                opacity: 0;
            }
            to {
                transform: scale(1);
                opacity: 1;
            }
        }
        .modal-title {
            font-size: 28px;
            color: #ff6b6b;
            margin-bottom: 20px;
        }
        .modal-score {
            font-size: 18px;
            margin: 15px 0;
            color: #666;
        }
        .modal-button {
            background-color: #ff6b6b;
            color: white;
            border: none;
            padding: 10px 30px;
            border-radius: 25px;
            font-size: 16px;
            cursor: pointer;
            transition: all 0.3s ease;
            margin-top: 20px;
        }
        .modal-button:hover {
            background-color: #ff5252;
            transform: scale(1.05);
        }
        .score-list {
            text-align: left;
            margin: 20px 0;
            padding: 0 20px;
        }
        .score-list-item {
            display: flex;
            justify-content: space-between;
            margin: 10px 0;
            padding: 5px 0;
            border-bottom: 1px solid #eee;
        }
    </style>
</head>
<body>
    <div class="game-title">贝利亚拼好饭消消乐</div>
    <div class="game-content">
        <div class="character-section">
            <div class="speech-bubble" id="speechBubble"></div>
            <img src="pictures/贝利亚.jpg" alt="贝利亚" class="character">
        </div>
        <div class="game-container">
            <div class="score-board">
                <div class="score-item">
                    <img src="pictures/杨国福.png" alt="杨国福">
                    <span>杨国福: <span id="score-杨国福">0</span></span>
                </div>
                <div class="score-item">
                    <img src="pictures/地锅鸡.png" alt="地锅鸡">
                    <span>地锅鸡: <span id="score-地锅鸡">0</span></span>
                </div>
                <div class="score-item">
                    <img src="pictures/肯德基.png" alt="肯德基">
                    <span>肯德基: <span id="score-肯德基">0</span></span>
                </div>
                <div class="score-item">
                    <img src="pictures/华莱士.png" alt="华莱士">
                    <span>华莱士: <span id="score-华莱士">0</span></span>
                </div>
                <div class="score-item">
                    <img src="pictures/可乐.png" alt="可乐">
                    <span>可乐: <span id="score-可乐">0</span></span>
                </div>
                <div class="score-item">
                    <img src="pictures/麦当劳.png" alt="麦当劳">
                    <span>麦当劳: <span id="score-麦当劳">0</span></span>
                </div>
            </div>
            <div class="game-board" id="gameBoard"></div>
        </div>
    </div>

    <div class="modal-overlay" id="gameOverModal">
        <div class="modal-content">
            <div class="modal-title">恭喜完成游戏！</div>
            <div class="modal-score">你的得分统计：</div>
            <div class="score-list" id="finalScoreList"></div>
            <button class="modal-button" onclick="restartGame()">再来一局</button>
        </div>
    </div>

    <script>
        const images = [
            { name: '杨国福', src: 'pictures/杨国福.png' },
            { name: '地锅鸡', src: 'pictures/地锅鸡.png' },
            { name: '肯德基', src: 'pictures/肯德基.png' },
            { name: '华莱士', src: 'pictures/华莱士.png' },
            { name: '可乐', src: 'pictures/可乐.png' },
            { name: '麦当劳', src: 'pictures/麦当劳.png' }
        ];

        // 创建卡片数组（每张图片出现两次）
        let cards = [...images, ...images];
        
        // 洗牌函数
        function shuffle(array) {
            for (let i = array.length - 1; i > 0; i--) {
                const j = Math.floor(Math.random() * (i + 1));
                [array[i], array[j]] = [array[j], array[i]];
            }
            return array;
        }

        // 初始化游戏
        function initGame() {
            const gameBoard = document.getElementById('gameBoard');
            gameBoard.innerHTML = '';
            cards = shuffle([...cards]);
            
            cards.forEach((card, index) => {
                const cardElement = document.createElement('div');
                cardElement.className = 'card';
                cardElement.dataset.index = index;
                cardElement.dataset.name = card.name;
                
                const img = document.createElement('img');
                img.src = card.src;
                img.alt = card.name;
                
                cardElement.appendChild(img);
                cardElement.addEventListener('click', handleCardClick);
                gameBoard.appendChild(cardElement);
            });
        }

        let selectedCards = [];
        let score = {};

        function handleCardClick(event) {
            const card = event.currentTarget;
            
            // 如果卡片已经匹配或已经选中，则忽略点击
            if (card.classList.contains('matched') || card.classList.contains('selected')) {
                return;
            }

            // 如果已经选中了两张卡片，则忽略点击
            if (selectedCards.length === 2) {
                return;
            }

            // 选中卡片
            card.classList.add('selected');
            selectedCards.push(card);

            // 如果选中了两张卡片
            if (selectedCards.length === 2) {
                const [card1, card2] = selectedCards;
                
                // 检查是否匹配
                if (card1.dataset.name === card2.dataset.name) {
                    // 匹配成功
                    setTimeout(() => {
                        card1.classList.add('matched');
                        card2.classList.add('matched');
                        selectedCards = [];
                        
                        // 更新分数
                        const name = card1.dataset.name;
                        score[name] = (score[name] || 0) + 1;
                        document.getElementById(`score-${name}`).textContent = score[name];
                        
                        // 检查游戏是否结束
                        checkGameEnd();
                    }, 500);
                } else {
                    // 匹配失败
                    setTimeout(() => {
                        card1.classList.remove('selected');
                        card2.classList.remove('selected');
                        selectedCards = [];
                    }, 1000);
                }
            }
        }

        function showGameOverModal() {
            const modal = document.getElementById('gameOverModal');
            const scoreList = document.getElementById('finalScoreList');
            scoreList.innerHTML = '';
            
            // 添加得分统计
            Object.entries(score).forEach(([name, count]) => {
                const scoreItem = document.createElement('div');
                scoreItem.className = 'score-list-item';
                scoreItem.innerHTML = `
                    <span>${name}</span>
                    <span>${count} 分</span>
                `;
                scoreList.appendChild(scoreItem);
            });
            
            modal.style.display = 'flex';
        }

        function restartGame() {
            const modal = document.getElementById('gameOverModal');
            modal.style.display = 'none';
            score = {};
            // 重置所有分数显示
            images.forEach(img => {
                document.getElementById(`score-${img.name}`).textContent = '0';
            });
            initGame();
        }

        function checkGameEnd() {
            const allCards = document.querySelectorAll('.card');
            const matchedCards = document.querySelectorAll('.card.matched');
            
            if (allCards.length === matchedCards.length) {
                setTimeout(() => {
                    showGameOverModal();
                }, 500);
            }
        }

        // 添加对话系统
        const foods = ['杨国福', '地锅鸡', '肯德基', '华莱士', '可乐', '麦当劳'];
        let currentFoodIndex = 0;

        function updateSpeechBubble() {
            const bubble = document.getElementById('speechBubble');
            const food = foods[currentFoodIndex];
            bubble.textContent = `我要吃${food}，否则破坏光之国，统治地球！`;
            bubble.classList.add('show');
            
            setTimeout(() => {
                bubble.classList.remove('show');
                currentFoodIndex = (currentFoodIndex + 1) % foods.length;
                setTimeout(updateSpeechBubble, 1000);
            }, 3000);
        }

        // 开始对话循环
        updateSpeechBubble();

        // 开始游戏
        initGame();
    </script>
</body>
</html> 